package demo05;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class DouDiZhu {
	public static void main(String[] args) {
		HashMap<Integer,String> pokerHash = new HashMap<Integer,String>();
		ArrayList<Integer> HashKey=new ArrayList<Integer>();//发下标，不发内容
		//准备牌
		String[] colors={"♠","♣","♦","♥"};
		String[] numbers={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
		
		int count = 0;
		pokerHash.put(count++,"大王");
		pokerHash.put(count++,"小王");
		//创建HashMap数据
		for(String number:numbers){
			for(String color:colors){
				pokerHash.put(count++,color+number);
			}
		}
		
		//洗牌 按照key来洗牌
		for (int i=0;i<54;i++) {  
			HashKey.add(i);
		}  
		Collections.shuffle(HashKey);
		
		Player p1=new Player();p1.setName("老王");
		Player p2=new Player();p2.setName("老李");
		Player p3=new Player();p3.setName("老六");
		ArrayList<Integer> dipai=new ArrayList<Integer>();
		//摸牌
		for(int i=0;i<54;i++){
			//获取每一张的牌
			int p = HashKey.get(i);
			if(i>=51){
				dipai.add(p);
			}else if(i%3==0){
				p1.getPoker().add(p);
			}else if(i%3==1){
				p2.getPoker().add(p);
			}else if(i%3==2){
				p3.getPoker().add(p);
			}
		}
		//排序手牌
		Collections.sort(p1.getPoker());
		Collections.sort(p2.getPoker());
		Collections.sort(p3.getPoker());
		//看牌
		showIt(p1,pokerHash);
		showIt(p2,pokerHash);
		showIt(p3,pokerHash);
		System.out.print("底牌:"+pokerHash.get(dipai.get(0))+",");
		System.out.print(pokerHash.get(dipai.get(1))+",");
		System.out.println(pokerHash.get(dipai.get(2)));
	}
	public static void showIt(Player p,HashMap<Integer,String> pokerHash){
		System.out.print(p.getName()+"的牌:");
		for(int i=0;i<17;i++){
			System.out.print(pokerHash.get(p.getPoker().get(i)));
			if(i!=16){
				System.out.print(",");
			}
		}
		System.out.println("");
	}
}



